package com.example.filter02.utils;


import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;

public class TimeUtil {

    /**
     * 获取当前时间的年月日时分秒 没有前导零
     * */
    public String returnNowDate() {
        Calendar calendar = Calendar.getInstance();

        return calendar.get(Calendar.YEAR) + "-"
                + (calendar.get(Calendar.MONTH) + 1) + "-"
                + calendar.get(Calendar.DAY_OF_MONTH) + " "
                + calendar.get(Calendar.HOUR_OF_DAY) + ":"
                + calendar.get(Calendar.MINUTE) + ":"
                + calendar.get(Calendar.SECOND);
    }

    /**
     * 获取有前导零的年月日时分秒
     * */
    public String returnZeroDate(){
        LocalDateTime nowTime = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return nowTime.format(dateTimeFormatter);
    }
}
